<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title> 小程序管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <style type="text/css">
        .layui-table{
            text-align: center;
        }
        .layui-table td, .layui-table th{
            text-align: center;
        }
    </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div id = "divhead"></div>
    <div class="layui-body">
        <form class="layui-form" action="" style = "margin-top: 30px;">
            <div class="layui-form-item">
                <label class="layui-form-label">图片:</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="img">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block" id="imglist">
                    <img style = "width:100px;height:150px" src = "{$res.kefu_haibao}"/>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                    <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                </div>
            </div>
            <input type="hidden" name="id" id = "id" value="{$res.id}"/>
        </form>
    </div>
</div>

<script id="pic" type="text/html">
    {{#  layui.each(d.pics, function(index, item){ }}
    <img class="layui-upload-img" src="{{ item }}" style="width: 100px; height: 100px;">
    {{#  }); }}
</script>
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/jquery-1.11.1.min.js" charset="utf-8"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    $(function(){
        $('#divhead').load('/index.php/Tongcheng/Index/menu/wid/2.html');
    })
    var pics = [{$vo.pics_arr}];
    layui.use(['element','laypage','laytpl','layer','upload', 'form'], function(){
        var upload = layui.upload,layer=layui.layer,form = layui.form,$=layui.jquery;
        //执行实例
        var uploadInst = upload.render({
            elem: '#img' //绑定元素
            ,url: '{:U("uploadFile")}' //上传接口
            ,multiple:false
            ,done: function(res){
                //上传完毕回调
                // layer.alert(res.url)
                $("#imglist").empty();
                $("#imglist").append("<img src = "+res.url+" style = 'width:150px;height:250px;'/>");
                $("#imglist").append("<input type = 'hidden' id = 'image' name = 'image' value = '"+res.url+"'/>");
            }
            ,error: function(){
                //请求异常回调
                layer.alert(res)
            }
        });
        form.on('submit(formDemo)', function(data){
            // layer.msg(''==parseInt(data.field.order));

            $.post('{:U("saveHaiBao")}',data.field,function(e){
                // layer.alert(e);
                if(1 == e){
                    layer.alert('添加成功');
                    setTimeout(function(){
                        window.parent.location.reload();
                    },2000);
                }else{
                    layer.alert('添加失败');
                }
            })
            return false;
        });
    });
</script>

</body>
</html>